#include<bits/stdc++.h>
using namespace std;

int check(int x, int y)
{
	if(x < 6*60 || y > 22*60 || y-x > 20 || y-x < 5)
		return false;
	else
		return true;
}

struct node
{
	int x, y;
	bool operator < (const node &a) const
	{
		return y < a.y;
	}
};

int main()
{
	int n;
	cin>>n;
	vector<node> s;
	
	int a, b, c, d;
	for(int i = 1;i <= n;i++)
	{
		cin>>a>>b>>c>>d;
		int x = a*60+b;
		int y = c*60+d;
		if(check(x, y))
			s.push_back({x, y});
	}
	sort(s.begin(), s.end());
	
	int pre = 0, ans = 0;
	for(int i = 0;i < s.size();i++)
	{
		if(s[i].x >= pre)
		{
			pre = s[i].y;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

